const Sequelize = require('sequelize');
const config = require('../config/default')

const { DATABASE, USERNAME, PASSWORD, HOST } = config.getDatabase();

const sequelise = new Sequelize(
    DATABASE,
    USERNAME,
    PASSWORD,
    {
        host: HOST,
        dialect: 'mysql',
        // 配置连接池
        pool: {
            max: 5,
            min: 0,
            acquire: 30000,
            idle: 10000
        },
        // 时区设置
        timezone: "+08:00"
    })

sequelise
    .authenticate()
    .then(() => {
        console.log('数据库连接成功')
    })
    .catch(err => {
        console.log(DATABASE, USERNAME, PASSWORD, HOST)
        throw new Error('数据库连接失败', err)
    })

module.exports = sequelise